package com.zr.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.service.LoginService;
import com.zr.serviceimpl.LoginServiceImpl;

public class LoginController extends HttpServlet{
		LoginService   ls = new LoginServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		  String uname = req.getParameter("uname");
		  	HttpSession  session  =req.getSession();
		  boolean  flag = ls.validateUser(uname);
		  if(flag){
			  session.setAttribute("uname", uname);
			  req.getRequestDispatcher("main.jsp").forward(req, resp);
		  }else{
			  req.getRequestDispatcher("index.jsp").forward(req, resp);
		  }
	}
	public static void main(String[] args) {
		System.out.println(111);
		System.out.println(222);
	}
}
